/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slicktemplate;

import java.util.ArrayList;
import org.newdawn.slick.*;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author andrew
 */
//similar to Level1.java, see comments there
public class Menu extends BasicGameState {

    ArrayList<ArrayList> renderList = new ArrayList<ArrayList>();
    ArrayList<ArrayList> updateList = new ArrayList<ArrayList>();
    int stateId = -1;
    Sound menuTheme;

    Menu(int stateId) {
        try {
            menuTheme = new Sound("sounds/themeMusic.ogg");
        } catch (Exception e) {
        }
        this.stateId = stateId;
        renderList.add(PlayButton.all);
        renderList.add(LevelEditButton.all);
        updateList.add(PlayButton.all);
        updateList.add(LevelEditButton.all);
    }

    @Override
    public void enter(GameContainer container, StateBasedGame game) throws SlickException {
        super.enter(container, game);
        menuTheme.loop();
    }
    
    

    @Override
    public void leave(GameContainer container, StateBasedGame game) throws SlickException {
        super.leave(container, game);
        menuTheme.stop();
    }

    
    
    @Override
    public int getID() {
        return stateId;
    }

    @Override
    public void init(GameContainer container, StateBasedGame game) throws SlickException {
        new PlayButton(50, 50);
        new LevelEditButton(300,50);
    }

    @Override
    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        for (ArrayList<Renderable> it : renderList) {//go through all the objects and draw them
            for (Renderable renderable : it) {
                renderable.render(g);
            }
        }
    }

    @Override
    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        Input input = container.getInput();
        for (ArrayList<Updateable> it : updateList) {//go through all the objects and update them
            for (int i = 0; i < it.size(); i++) {
                Updateable obj = it.get(i);
                if (obj.update(input, game)) {
                    it.remove(obj);
                    i--;
                }
            }
        }
    }
}
